// Widgets/Personals/FriendsPetChat/FriendsPetChat.js
//获取应用实例
const app = getApp();
const assetsAddress = app.globalData.global.assetsIp + '/' + app.globalData.global.assetsName;
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    item: {
      type: Object,
      value: {},
    },
    pet: {
      type: Object,
      value: {},
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    assetsAddress: assetsAddress,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 页面跳转
    goNext(e){
      let _this = this;
      console.log('123123')
      let type = e.target.dataset.type||e.currentTarget.dataset.type;
      let url = e.target.dataset.name||e.currentTarget.dataset.name;
      let item = e.target.dataset.item||e.currentTarget.dataset.item;
      // console.log(JSON.stringify(item))
      // return
      if(item){
        if(type == 1){
          wx.switchTab({
            url: `${url}`,
          })
        }else{
          wx.navigateTo({
            url: `${url}?item=${JSON.stringify(item)}`,
          })
        }
      }else{
        if(type == 1){
          wx.switchTab({
            url: `${url}`,
          })
        }else{
          wx.navigateTo({
            url: `${url}`,
          })
        }
      }
    },
    applyMatings(e){
      let url = e.target.dataset.name||e.currentTarget.dataset.name;
      let item = e.target.dataset.item||e.currentTarget.dataset.item;
      this.triggerEvent('applyMatings', {'url': url,'item': JSON.stringify(item)})
    },
    // 聊天
    toChat(e){
      let _this = this;
      let item = e.target.dataset.item||e.currentTarget.dataset.item;
      console.log(item,'item')
      wx.navigateTo({
        url: `/pages/Chat/Chat?userId=${_this.properties.pet.id.toString()}&conversationID=C2C${item.To_Account}`,
      })
    }
  }
})